#define	TOTAL_BITMAP	32768
unsigned int bitmap[TOTAL_BITMAP];
unsigned long int size_ram();
unsigned long int get_sizeram(int tipo);
unsigned long int get_numpag();
void* malloc(unsigned int size);
void virtualmem_init();


unsigned long int totale_ram_installata;
#define	MAX_GDT	8192
#define	GDT_USE	6
#define	GDT_DIM	8
// struttura della GDT
struct gdt_descr {
	unsigned short limite;
	unsigned short base0_15;
	unsigned char base16_23;
	unsigned char base24_31;
	unsigned char attributi0_7;
	unsigned char attributi8_15;
};

void add_gdt(unsigned short limite,unsigned long int base,unsigned char att0_7,unsigned char att8_15);
void load_gdt(struct gdt_descr *base);
void init_gdt();

// ### privileggi e attributi della GDT ###

// byte access
#define	PRESENT		0x80
// privileggi
#define	LEVEL0		0x00
#define	LEVEL1		0x20
#define	LEVEL2		0x40
#define	LEVEL3		0x60
// segmento
#define	SEGMENT		0x10
// eseguibile
#define	EXECUTABLE	0x10
// espansione
#define	EXPANSION	0x4
// scrittura / lettera
#define	WRITE_READ	0x2

// flag
#define	GRANULARITY	0x8
#define	DEF_SIZE		0x8


#define	STANDARD_CODE_SEGMENT	(PRESENT | SEGMENT | EXECUTABLE | WRITE_READ)
#define	STANDARD_DATA_SEGMENT	(PRESENT | SEGMENT | WRITE_READ)
#define	KERNEL_CODE_SEGMENT		(STANDARD_CODE_SEGMENT | LEVEL0)
#define	KERNEL_DATA_SEGMENT		(STANDARD_DATA_SEGMENT | LEVEL0)
#define	USER_CODE_SEGMENT			(STANDARD_CODE_SEGMENT | LEVEL3)
#define	USER_DATA_SEGMENT			(STANDARD_DATA_SEGMENT | LEVEL3)

// mi lascio la strada per il multi tasking
#define	TSS_SEGMENT					(PRESENT | LEVEL0 | EXECUTABLE | 1)
#define	TSS_FLAGS					0

#define	DEFAULT_FLAGS				(GRANULARITY | DEF_SIZE)

#define	KERNEL_CODE					0x80
#define	KERNEL_DATA					0x10
#define	USER_CODE					0x18
#define	USER_DATA					0x20


//  ### PAGING ###
#define	PAGE_SIZE		4
#define	PAG_PRESENT		1
#define	PAG_READWRITE	2
#define	SUPERVISOR		4
#define	WRITE_THROUGH	8
#define	CACHE_DISABLE	16
#define	ACCESSED			32
#define	DIRTY				64
#define	PAGE_4MB			128
#define	GLOBAL			256

#define	KERNEL_PAGES_FLAG		PAG_PRESENT | PAG_READWRITE
#define	USER_PAGES_FLAG		PAG_PRESENT	| PAG_READWRITE | SUPERVISOR

void init_paging();
void abilita_paging();
void disabilita_paging();
